package com.libbase.kotlin.presenter

import com.base.kotlin.mvp.BasePresenter
import com.libbase.kotlin.NyqfModel
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers

class NyqfPresenter : BasePresenter<NyqfContract.View, NyqfContract.Model>(), NyqfContract.Presenter {

    override fun getTitles() {
        if (isViewAttached()) {
            mView?.showLoading()
            try {
                val disposable = mModel?.getTitles()?.subscribeOn(Schedulers.io())
                        ?.observeOn(AndroidSchedulers.mainThread())?.subscribe { result ->
                            mView?.hideLoading()
                            mView?.onSuccessNyqfTitle(result)
                        }
                disposable?.let { mDisposables.add(it) }
            } catch (e: RuntimeException) {
                mView?.hideLoading()
                mView?.onError(e)
            }
        }
    }

    override fun getModel(): NyqfContract.Model? {
        return NyqfModel()
    }
}